//
//  FCCSearchBar.m
//  FuChengCompany
//
//  Created by fly on 2019/2/18.
//  Copyright © 2019年 fly. All rights reserved.
//

#import "FCCSearchBar.h"
#import "WJCDefine.h"

@implementation FCCSearchBar

+ (instancetype)searchBar
{
    return [[self alloc] init];
}
-(void)awakeFromNib{
    [super awakeFromNib];
    self.backgroundColor = [UIColor whiteColor];
    self.placeholder = @"搜索";
    // 设置内容 -- 垂直居中
    self.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    
    UIView *leftView = [[UIView alloc] initWithFrame:(CGRect){0, 0, 44, 38}];
    // 设置左边显示一个放大镜
    UIImageView *searchIcon = [[UIImageView alloc] init];
    searchIcon.image = [UIImage imageNamed:@"ic_search"];
    searchIcon.width = 30;
    searchIcon.height = 30;
    searchIcon.centerY = 22;
    searchIcon.contentMode = UIViewContentModeCenter;
    [leftView addSubview:searchIcon];
    self.leftView = leftView;
    
    // 设置左边的view永远显示
    self.leftViewMode = UITextFieldViewModeAlways;
    
    // 设置右边永远显示清除按钮
    self.clearButtonMode = UITextFieldViewModeAlways;
    self.returnKeyType = UIReturnKeySearch;
    self.layer.cornerRadius = 22;
//    self.layer.borderColor =  HEXC(0xF5F5F5).CGColor;
//    self.layer.borderWidth=0.5;
    self.font = font13;
}
-(instancetype)init{
    if (self = [super init]) {
        self.backgroundColor = [UIColor whiteColor];
        self.placeholder = @"搜索";
        self.frame = CGRectMake(0, 0, WJCScreenW, 44);
        // 设置内容 -- 垂直居中
        self.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
        
        UIView *leftView = [[UIView alloc] initWithFrame:(CGRect){0, 0, 30, 30}];
        // 设置左边显示一个放大镜
        UIImageView *searchIcon = [[UIImageView alloc] init];
        searchIcon.image = [UIImage imageNamed:@"ic_search"];
        searchIcon.width = 30;
        searchIcon.height = 30;
        searchIcon.contentMode = UIViewContentModeCenter;
        [leftView addSubview:searchIcon];
        self.leftView = leftView;
        
        // 设置左边的view永远显示
        self.leftViewMode = UITextFieldViewModeAlways;
        
        // 设置右边永远显示清除按钮
        self.clearButtonMode = UITextFieldViewModeAlways;
        self.returnKeyType = UIReturnKeySearch;
        self.layer.cornerRadius = 22;
        self.layer.borderColor =  HEXC(0xF5F5F5).CGColor;
        self.layer.borderWidth=0.5;
        self.font = font13;
    }
    return self;
}
- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // 设置背景
//        self.background = [UIImage imageNamed:@"searchbar_textfield_background"];
        
        self.backgroundColor = [UIColor whiteColor];
        self.placeholder = @"搜索";
        
        // 设置内容 -- 垂直居中
        self.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
        
        UIView *leftView = [[UIView alloc] initWithFrame:(CGRect){0, 0, 30, 30}];
        // 设置左边显示一个放大镜
        UIImageView *searchIcon = [[UIImageView alloc] init];
        searchIcon.image = [UIImage imageNamed:@"ic_search"];
        searchIcon.width = 30;
        searchIcon.height = 30;
        searchIcon.contentMode = UIViewContentModeCenter;
        [leftView addSubview:searchIcon];
        self.leftView = leftView;
        
        // 设置左边的view永远显示
        self.leftViewMode = UITextFieldViewModeAlways;
        
        // 设置右边永远显示清除按钮
        self.clearButtonMode = UITextFieldViewModeAlways;
        self.returnKeyType = UIReturnKeySearch;
        self.layer.cornerRadius = frame.size.height*0.5;
        self.layer.borderColor =  HEXC(0xF5F5F5).CGColor;
        self.layer.borderWidth=0.5;
        self.font = font13;
    }
    return self;
}

@end
